<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>

<script type="text/javascript">
$(function() {
     parent.$.messager.progress('close');

     $('#form').form({
         url : contextPath+"/company/addCompany.action",
         onSubmit : function() {
             parent.$.messager.progress({
                 title : var_alert_title,
                 text : var_data_processing
             });
             //检查Form参数合法性,返回false不提交
            if(!checkForm()){
                parent.$.messager.progress('close');
                 return false;
             }
         },
         success : function(data) {
             parent.$.messager.progress('close');
             data = JSON.parse(data);
             if(data && "success" == data.result){
            	 parent.$.messager.alert(var_alert_title, data.msg, 'info');
            	 parent.$.modalDialog.handler.dialog('close');
           	     parent.$.modalDialog.openner_dataGrid.datagrid('reload');
             } else {
                 parent.$.messager.alert(var_common_error, data.msg, 'error');
             }
         }
     });
});

function checkForm(){
	var isValid = true;
	var checkHasDefaultUrl = contextPath + "/company/checkDefaultCompany.action";
	
	var expComName = $("#form").find("[name='expComName']").validatebox({
	    required: true
	});
	isValid = isValid && expComName.validatebox('isValid');
	
	var expComAddress = $("#form").find("[name='expComAddress']").validatebox({
	    required: true
	});
	isValid = isValid && expComAddress.validatebox('isValid');
	
	var companyName = $("#form").find("[name='companyName']").validatebox({
	    required: true
	});
	isValid = isValid && companyName.validatebox('isValid');
	
	var companyAddress = $("#form").find("[name='companyAddress']").validatebox({
	    required: true
	});
	isValid = isValid && companyAddress.validatebox('isValid');
	
	var companyTel = $("#form").find("[name='companyTel']").validatebox({
	    required: true
	});
	isValid = isValid && companyTel.validatebox('isValid');
	
	var companyFax = $("#form").find("[name='companyFax']").validatebox({
	    required: true
	});
	isValid = isValid && companyFax.validatebox('isValid');
	
	
	var benBankName = $("#form").find("[name='benBankName']").validatebox({
	    required: true
	});
	isValid = isValid && benBankName.validatebox('isValid');
	
	var benBankCode = $("#form").find("[name='benBankCode']").validatebox({
	    required: true
	});
	isValid = isValid && benBankCode.validatebox('isValid');
	
	var swiftCode = $("#form").find("[name='swiftCode']").validatebox({
	    required: true
	});
	isValid = isValid && swiftCode.validatebox('isValid');
	
	//var companyEmail = $("#form").find("[name='companyEmail']").validatebox({
		//validType:'email'
	//});
	//isValid = isValid && companyEmail.validatebox('isValid');
	
	if($('#isDefault').val() == 'true'){
		var isDefault = $("#form").find("[name='isDefault']").validatebox({
			validType:['remoteValid[\''+checkHasDefaultUrl+'\',\'isDefault\',\'<s:text name="erp.business.crm.company.hasdefault"></s:text>\']']
		});
		isValid = isValid && isDefault.validatebox('isValid');
	}
	
	return isValid;
}
</script>
<div id="add-edit-dialog">
        <div class="p5">
            <form id="form" name="form" action="" method="post">
                <table class="tablewidth1">
                	<tr>
                		<td align="right">
                			<s:text name="erp.business.crm.company.inexcompname"></s:text>：
                		</td>
                		<td align="left">
                			<input id="expComName" name="expComName" style="width:520px;height: 20px;" type="text"/>
                		</td>
                	</tr>
                	<tr>
                		<td align="right">
                			<s:text name="erp.business.crm.company.inexcompaddress"></s:text>：
                		</td>
                		<td align="left">
                			<input id="expComAddress" name="expComAddress" style="width:520px;height: 20px;"  type="text" />
                		</td>
                	</tr>
                	<tr>
                		<td align="right">
                			<s:text name="erp.business.crm.company.name"></s:text>：
                		</td>
                		<td align="left" colspan="3">
                			<input id="companyName" name="companyName" style="width:520px;height: 20px;"  type="text"/>
                		</td>
                	</tr>
                	<tr>
                		<td align="right">
                			<s:text name="erp.business.crm.company.address"></s:text>：
                		</td>
                		<td align="left" colspan="3">
                			<input id="companyAddress" name="companyAddress" style="width:520px;height: 20px;"  type="text"/>
                		</td>
                	</tr>
                	<tr>
                		<td align="right">
                			<s:text name="erp.business.crm.company.email"></s:text>：
                		</td>
                		<td align="left" colspan="3">
                			<input id="companyEmail" name="companyEmail" style="width:520px;height: 20px;"  type="text"/>
                		</td>
                	</tr>
                	<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.mobile"></s:text>：
	        			</td>
	        			<td>
	        				<input id="companyMob" name="companyMob" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.telephone"></s:text>：
	        			</td>
	        			<td>
	        				<input id="companyTel" name="companyTel" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.fax"></s:text>：
	        			</td>
	        			<td>
	        				<input id="companyFax" name="companyFax" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
					<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.bankname"></s:text>：
	        			</td>
	        			<td>
	        				<input id="benBankName" name="benBankName" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.bankcode"></s:text>：
	        			</td>
	        			<td>
	        				<input id="benBankCode" name="benBankCode" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.bankidentifycode"></s:text>：
	        			</td>
	        			<td>
	        				<input id="swiftCode" name="swiftCode" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.accountuser"></s:text>：
	        			</td>
	        			<td>
	        				<input id="acName" name="acName" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.accountcode"></s:text>：
	        			</td>
	        			<td>
	        				<input id="acCode" name="acCode" style="width:520px;height: 20px;" type="text"/>
	        			</td>
        			</tr>
        			<tr>
	        			<td align="right">
	        				<s:text name="erp.business.crm.company.isdefault"></s:text>：
	        			</td>
	        			<td>
	        				<select id="isDefault" name="isDefault" style="height: 28px;line-height: 26px;width:95px;">
	        					<option value="false"><s:text name="erp.select.choose"></s:text></option>
	        					<option value="true"><s:text name="erp.yes"></s:text></option>
	        					<option value="false"><s:text name="erp.no"></s:text></option>
	        				</select>
	        			</td>
        			</tr>
                </table>
               
                <div class="fn-clear"></div>
            </form>
        </div>
    </div> 